<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Karaoke.pe</title>
	
	<%@include file="scripts.jsp" %>
    <%@page import="java.util.Collection"%>
<%@page import="karaoke.modelo.Sala"%>
<%@page import="karaoke.modelo.Local"%>
<%@page import="karaoke.modelo.Cliente"%>
<%@page import="karaoke.negocio.GestionLocales"%>	
<%@page import="karaoke.negocio.GestionSalas"%>	
<%@page import="karaoke.negocio.GestionClientes"%>	


			
</head>
<body class="preview" id="top">
	
	<%
	//out.println(DateFormat.getFechaHoraSave("13/06/2013", "12:00 a.m."));
	
	/*validamos existencia de sesion*/
	String nombreuser = "";
	HttpSession sesion = request.getSession();
	Cliente user = (Cliente)sesion.getAttribute("CLIENTE");
	boolean logeado = false;
	int idcliente = 0;
	
	if (user == null) {
		response.sendRedirect("login-register-user.jsp");
	} else {
		if (sesion.getAttribute("login") == null){
			sesion.setAttribute("login", "true");
		} else {
			logeado = Boolean.parseBoolean(sesion.getAttribute("login").toString());
		}
		nombreuser = user.getNombres()+" "+user.getPaterno()+" "+user.getMaterno();
		idcliente = user.getIdcliente();
	}
	
	String indicador = request.getParameter("logout");
	if (indicador != null){
		sesion.removeAttribute("CLIENTE");
		response.sendRedirect("index.jsp");
	}

%>
<jsp:include page="header_cliente.jsp"></jsp:include>

<div class="container">
<form class="form-horizontal" action="ComentarioRegistrarServlet" method="post" id="FormComentario" name="FormComentario" onsubmit="operarCom(); return false;">


<fieldset>

<!-- Form Name -->

<legend>HU09. Comentar acerca de las Salas</legend>
<!-- Select Basic -->
		<div id="idComoperamsg" class="alert">
       <button type="button" class="close" data-dismiss="alert">&times;</button>
	   <div id="msjComresultados"></div>
	</div>
	<div class="spacer"></div> 
	<div class="spacer"></div>
	<div class="control-group" class="span6">
	  <label class="control-label">Usuario</label>
	  	
	  <div class="controls">
	    <%
	    if (user != null) {
	    	out.println("<input type='text' name='Cliente' id='Cliente' class='input-xlarge' value='"+user.getCorreo()+""+"' readonly='readonly'/>");
	    	out.println("<input type='text' name='idCliente' id='idCliente' class='input-mini' value='"+user.getIdcliente()+""+"' readonly='readonly'/>");
	    }
	    	%>
	  </div>
	</div>

<!-- Select Basic -->
<div class="control-group" class="span6">
  <label class="control-label">Local</label>
  <div class="controls">
    <select id="idLocal" name="idLocal" class="input-xlarge">
    <%
	Collection<Local> locales = null;
	GestionLocales negocio = new GestionLocales();
	
	 locales = negocio.listar();
	String idLocalInicial=request.getParameter("idLocal");
    
	if (locales != null) {
		  out.println("<option selected value=''>..: Seleccione Local :..</option>"); 

	for (Local l :locales)
	{
		 int valLocal=l.getIdlocal();
			if (idLocalInicial==null){
				idLocalInicial=l.getIdlocal()+"";
			}
				
	   if ( (valLocal+"").equals(idLocalInicial))
		{
		  out.println("<option value="+l.getIdlocal()+">"+l.getNombre()+"</option>"); }
		  else
		  {
	      out.println("<option value="+l.getIdlocal()+">"+l.getNombre()+"</option>");  
		  }
  	}
	}
	%>  


    </select>
  </div>
</div>

<div class="control-group" class="span6">
  <label class="control-label">Sala</label>
  <div class="controls">
    <select id="idSala" name="idSala" class="input-xlarge">
    
    </select>
  </div>
</div>

<!-- Text input-->
<div class="control-group" class="span6">
  <label class="control-label">Fecha de Visita</label>
  <div class="controls">
  	<input type="date" name="FechaVisita" id="FechaVisita" class="input-medium"  required = "required"/>
           
  </div>
</div>
<!-- Multiple Radios (inline) -->
<div class="control-group">
  <label class="control-label">Calificaci&oacute;n</label>
  <div class="controls">
    <label class="radio inline">
      <input type="radio" name="Calificacion" value="1" >
      1
    </label>
    <label class="radio inline">
      <input type="radio" name="Calificacion" value="2">
      2
    </label>
    <label class="radio inline">
      <input type="radio" name="Calificacion" value="3">
      3
    </label>
    <label class="radio inline">
      <input type="radio" name="Calificacion" value="4">
      4
    </label>
    <label class="radio inline">
      <input type="radio" name="Calificacion" value="5" checked="checked">
      5
    </label>
  </div>
 </div>

<!-- Textarea -->
<div class="control-group">
  <label class="control-label">Comentario</label>
  <div class="controls">                     
    <textarea rows="5" id="Comentario" name="Comentario" class="input-xlarge" required = "required"></textarea>
  </div>
</div>
			
<!-- Button (Double) -->
<div class="control-group" class="span8">
  <div class="controls" class="span2">
    <button id="BotonRegistrar"  name="BotonRegistrar" class="btn btn-medium btn-primary"  type="submit">Registrar</button>
    <button id="BotonLimpiar"      name="BotonLimpiar" class="btn btn-medium btn-primary" type="reset">&nbsp;&nbsp;Limpiar&nbsp;&nbsp;</button>
    </div>
</div>



</fieldset>


</div>
<div class="spacer"></div>

</form>

<%@include file="footer.jsp" %>

 </div> <!-- /container -->
<script type="text/javascript">

var Comoperamsg = $("#idComoperamsg");
var Comload = $(".progress");
Comoperamsg.hide();
Comload.hide();

function operarCom(){
	var Comform = $("#FormComentario");
	var Comdivmsg = Comoperamsg.find("div#msjComresultados");
	var Combutton = $("#BotonRegistrar");
	//cargador
	Comoperamsg.removeClass("alert-info").fadeIn("fast");
	Comload.show();
	Combutton.attr("disabled", true);
	
	var request = $.ajax({
	  url: Comform.attr("action"),
	  type: "POST",
	  data: Comform.serialize(),
	  dataType: "json"
	});
	
	
	request.done(function(msg) {
		Comload.hide();
		Comdivmsg.html( msg.mensaje );
		Comoperamsg.addClass(msg.claseMsg).delay(2000).fadeOut("slow", function(){
			Combutton.attr("disabled", false);
			if (msg.tipoMsg == "success") {
				$("#FormComentario").trigger("reset");
			}
		});
		console.log(msg);
	});
	
	request.fail(function(jqXHR, textStatus) {
		Comload.hide();
      	Comdivmsg.html("Request failed: " + textStatus);
      	Combutton.attr("disabled", false);     
		
	});
	
	return false;
}

$("#idLocal").change(function(){
	var idlocal = $(this).val();
	
	cargaSala(idlocal, 0);
});

function cargaSala(idlocal, idsala){
	$.ajax({
		url: "/KaraokeMasters/ConsultaSalaLocalServlet",
		type: "POST",
		data: { idlocal: idlocal, idsala: idsala },
		dataType: "html"
	}).done(function(html){
		$("#idSala").html(html);
		//console.log(html);
	}).fail(function(jqXHR, textStatus) {
	  alert( "Request failed: " + textStatus );
	});
}

</script>
 <%@include file="lejavascript.jsp" %>
	
</body>
</html>